package app.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 文件工具类
 * @author zoe
 *
 */
public class FileUtil {
	
	/**
	 * 获取文件编码
	 * @param path
	 * @return
	 */
	public String getFileCode(String path){
		File file = new File(path);  
		InputStream in;
		try {
			in = new FileInputStream(file);
			byte[] b = new byte[3];  
			in.read(b);  
			in.close();  
			if (b[0] == -17 && b[1] == -69 && b[2] == -65)  
			    return "UTF-8";  
			else  
				return "GBK";
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "GBK";  
		
	}

}
